package org.tp8.sampleapp.service.facade;

import java.util.Collection;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.tp8.sampleapp.exc.SampleAppException;
import org.tp8.sampleapp.model.Student;
import org.tp8.sampleapp.rule.model.RuleModelWrapper;
import org.tp8.sampleapp.service.intf.StudentService;

/**
 * The Class CourseFacade.
 */
@Service("studentFacade")
public class StudentFacade extends AbstractFacade {

	/**
	 * The student service.
	 */
	@Autowired
	private StudentService studentService;

	/**
	 * Find all.
	 * 
	 * @return the collection
	 * @throws SampleAppException
	 *             the sample app exception
	 */
	public Collection<Student> findAll() throws SampleAppException {
		Pageable pageable = new PageRequest(0, 100);
		Page<Student> page = studentService.findAll(pageable);
		return page.getContent();
	}

	/**
	 * Save.
	 * 
	 * @param student
	 *            the student
	 * @throws SampleAppException
	 *             the sample app exception
	 */
	public Student save(Student student) throws SampleAppException {
		return studentService.save(student);
	}

	/**
	 * Find one.
	 * 
	 * @param id
	 *            the id
	 * @return the student
	 * @throws SampleAppException
	 *             the sample app exception
	 */
	public Student findOne(Long id) throws SampleAppException {
		return studentService.findOne(id);
	}

	/**
	 * Delete.
	 * 
	 * @param id
	 *            the id
	 * @throws SampleAppException
	 *             the sample app exception
	 */
	public void delete(Long id) throws SampleAppException {
		studentService.delete(id);
	}

	/**
	 * Validate.
	 * 
	 * @param sessionName
	 *            the session name
	 * @param entity
	 *            the entity
	 * @return the rule model wrapper
	 * @throws SampleAppException
	 *             the sample app exception
	 */
	public RuleModelWrapper validate(String sessionName, Student entity)
			throws SampleAppException {
		return studentService.validate(entity);
	}

	/**
	 * Count.
	 * 
	 * @return the long
	 * @throws SampleAppException
	 */
	public long count() throws SampleAppException {
		return studentService.count();
	}
}
